package com.zsh.demo.controller;

import com.alibaba.fastjson.JSON;
import com.zsh.demo.pojo.User;
import com.zsh.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class LoginController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public ResponseEntity login(@RequestBody User user) {
        User users = userService.findByUser(user.getUsername(), user.getPassword());
        String flag = "error";
//        System.out.println(users);
        HashMap<String, Object> map = new HashMap<>();
        if (users != null) {
            flag = "ok";
        }
        map.put("flag", flag);
        map.put("users", users);
        return ResponseEntity.ok().body(map);

    }
}